package com.mk.service.platform;

import act.controller.Controller;
import com.github.d925529.apidoc.ApiHttpMethod;
import com.github.d925529.apidoc.annotation.Api;
import com.github.d925529.apidoc.annotation.ApiMethod;
import com.github.d925529.apidoc.annotation.ApiParam;
import com.github.d925529.apidoc.annotation.ApiReturn;
import com.mk.domain.CpRoleUser;
import com.mk.interceptor.ITranslate;
import com.mk.util.S2;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.PostAction;
import org.osgl.mvc.annotation.PutAction;
import org.osgl.mvc.annotation.With;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;

/**
 * 说明：用户角色后台服务
 * 作者：刘永盛
 * 日期：2018-7-30 11:48:40
 * 版本：1.0.0
 */
@Controller("cpRoleUser")
@Api(group = "pl", title = "用户角色服务", path = "/cpRoleUser")
@SuppressWarnings("unused")
public class CpRoleUserService extends BasePlatformService {
    @Inject
    private CpRoleUser.Mapper cpRoleUserMapper;


    @With({ILogin.class, ITranslate.class})
    @PostAction("add.json")
    @ApiMethod(title = "增加保存用户角色", path = "/add.json", method = ApiHttpMethod.POST)
    @ApiParam(name = "cpRoleUser", title = "用户角色", type = CpRoleUser.class)
    @ApiReturn(description = "主键", type = String.class)
    public String add(@NotNull CpRoleUser cpRoleUser) {
        String id = S2.UUID();
        cpRoleUser.setRoleid(id);
        cpRoleUserMapper.insertTemplate(cpRoleUser);
        return id;
    }


    @With({ILogin.class, ITranslate.class})
    @PutAction("update.json")
    @ApiMethod(title = "修改保存用户角色", path = "/update.json", method = ApiHttpMethod.PUT)
    @ApiParam(name = "cpRoleUser", title = "用户角色", type = CpRoleUser.class)
    @ApiReturn(description = "修改了的数量", type = int.class)
    public int update(@NotNull CpRoleUser cpRoleUser) {
        return cpRoleUserMapper.updateTemplateById(cpRoleUser);
    }

    @With(ILogin.class)
    @GetAction("view.json")
    @ApiMethod(title = "查询指定用户角色", path = "/view.json", method = ApiHttpMethod.GET)
    @ApiParam(name = "id", title = "用户角色的主键", type = String.class)
    @ApiReturn(description = "用户角色", type = CpRoleUser.class)
    public CpRoleUser view(@NotNull String id) {
        return cpRoleUserMapper.single(id);
    }
}
